package com.wrb.coupon.controller.microservice;

import com.wrb.coupon.exception.ServiceException;
import com.wrb.coupon.response.ServerResponse;
import com.wrb.coupon.service.CouponService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

/**
 * @author Wrb
 * @date 2019/12/20 16:10
 */
@RestController
@RequestMapping("/micro/coupon")
@CrossOrigin(origins = "*", methods = {RequestMethod.POST, RequestMethod.GET})
@Api(tags = "优惠券服务内部调用")
public class MicroCouponController {

	@Autowired
	private CouponService couponService;

	@RequestMapping(value = "/generateCustomerCoupon", method = RequestMethod.POST, produces = "application/json; charset=utf-8")
	@ApiOperation(value = "发放用户优惠券")
	public ResponseEntity generateCustomerCoupon(
			@ApiParam(required = true, value = "会员id") @RequestParam(required = true) long customerId,
			@ApiParam(required = true, value = "优惠券模板id") @RequestParam(required = true) long couponTemplateId,
			@ApiParam(required = true, value = "来源") @RequestParam(required = true) String source
	) throws ServiceException {
		return ServerResponse.success(this.couponService.generateCustomerCoupon(customerId, couponTemplateId, source));
	}
}
